<template>
  <div class="mod-config">
    <basic-container>
      <div class="boxsty zhiBiao" v-if="showH ==1">
            <div style="border-top: 1px solid #b0bde2">
                <div class="mt10">
                    <div style="float:right">
                       <el-button type="primary" @click="okAll" v-loading.fullscreen.lock="fullscreenLoading">批量同意</el-button>
                       <el-button type="primary" @click="backAll">批量驳回</el-button>
                       <el-button type="primary" @click="fanHu">返回</el-button>
                    </div>
                </div>
            </div>
            <el-table :data="dataList"
                    style="width: 100%;margin-top:20px" height="60vh"
                    ref="tableRef">
                <el-table-column :selectable='checkboxSelect' type="selection" width="55" header-align="center" align="center"></el-table-column>
                <el-table-column type="index" width="80" header-align="center" align="center" label="序号"></el-table-column>
                <el-table-column prop="shouyueName" label="受约人姓名" min-width="120" show-overflow-tooltip header-align="center" align="center"></el-table-column>
                <el-table-column prop="zhibiaoType" label="指标类别" min-width="120" header-align="center" align="center"></el-table-column>
                <el-table-column prop="zhibiaoName" label="指标名称" min-width="120" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column prop="weight" label="权重" min-width="120" header-align="center" align="center"></el-table-column>
                 <el-table-column prop="formulaId" label="计算公式" min-width="180" header-align="center" align="center">
                      <template slot-scope="scope">
                              <span v-if="scope.row.formulaId == null">无公式</span>
                                    <el-select v-else  v-model="scope.row.formulaId" placeholder="请选择" size="mini" disabled>
                                        <el-option
                                          v-for="item in formulaOptions"
                                          :key="item.id"
                                          :label="item.gsMc"
                                          :value="item.id">
                                        </el-option>
                                    </el-select>
                      </template>
                </el-table-column>
                <el-table-column prop="targetValue" label="目标值" min-width="120" header-align="center" align="center"></el-table-column>
                <el-table-column prop="unit" label="单位" min-width="120" header-align="center" align="center"></el-table-column>
                <el-table-column prop="ytbSz" label="填报值(预)" min-width="120" header-align="center" align="center">
                  <template slot-scope="scope">
                      <span>{{scope.row.ytbSz}}</span>
                  </template>
                </el-table-column>
                <el-table-column prop="tbSz" label="填报值" min-width="120" header-align="center" align="center">
                  <template slot-scope="scope">
                    <span >{{scope.row.tbSz}}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="zbDf"
                  header-align="center"
                  align="center"
                  min-width="100"
                  label="得分">
                  <template slot-scope="scope">
                    <el-popover
                      placement="left"
                      width="300"
                      trigger="hover">
                      <p>考核得分：{{scope.row.zbDf}}</p>
                      <span v-if="scope.row.ytbSzfrac!=null && scope.row.tbSzfrac!=null">
                        <p >填报加扣分：{{scope.row.tbSzfrac}}</p>
                        <p >原因：{{scope.row.tbSzfracre}}</p>
                      </span>
                      <span v-else-if="scope.row.ytbSzfrac!=null && scope.row.tbSzfrac==null">
                        <p >预填报加扣分：{{scope.row.ytbSzfrac}}</p>
                        <p >原因：{{scope.row.ytbSzfracre}}</p>
                      </span>
                      <span v-else-if="scope.row.ytbSzfrac==null && scope.row.tbSzfrac!=null">
                        <p >填报加扣分：{{scope.row.tbSzfrac}}</p>
                        <p >原因：{{scope.row.tbSzfracre}}</p>
                      </span>
                      <div slot="reference" class="name-wrapper">
                        <span style="color:#ff3300">{{scope.row.zbDf}}</span>
                      </div>
                    </el-popover>

                  </template>
                </el-table-column>
                <el-table-column
                  prop="signLevel"
                  header-align="center"
                  min-width="100"
                  align="center"
                  label="合同级别" :formatter="statusFormater">

                </el-table-column>
                <el-table-column prop="auditStatus" label="状态" min-width="120" header-align="center" align="center" :formatter="tbzbStatusFormater">
                </el-table-column>
            </el-table>
      </div>
      <hetongcjTable v-if="showH ==2" @hetongcjC="hetongcjC" :hetongzhibiaoTable='hetongzhibiaoTable' ></hetongcjTable>
    </basic-container>
  </div>
</template>

<script>

import {getPage, okApi, tbshokAllApi, backApi, tbshbackAllApi, getPageChild, okAllChildApi, backAllChildApi,getFormula} from '@/api/hetongrenwu/hetongyeji/hetongzb'
import {radioTwoList} from '@/api/hetongrenwu/hetonghtxxdjb'
import { validatenull } from "@/util/validate";
import { getMainOrChild } from '@/api/workflow/ht'
import hetongcjTable from "@/views/hetongrenwu/components/hetongcj-table"

export default {
    components:{
        hetongcjTable,
    },
    data(){
        return{
            form:{},
            streamId: Number,
            streamType: '',
            radio:'1',
            radioTwo:"-1",
            dataList:[],
            pageIndex:1,
            pageSize: 10,
            totalPage: 0,
            searchadvanced: true,
            searchheight: '0',
            radioTwoList:radioTwoList,
            showH:1,
            hetongId:Number,
            hetongzhibiaoTable:{
              lastPage:'zbsh',
              showSearch:true,
              pageTitle:'业绩合同',
              showBackBtn:false
            },
            programInterface: '',
            formulaOptions: [],
            fullscreenLoading:false,
            fullscreenLoading2:false,
        }
    },
    watch:{
      radio(value){
        if(value){
          this.getDataList();
        }
      },
      radioTwo(value){
        if(value){
          this.getDataList();
        }
      }
    },
    created() {
      this.getFormula();
    },
    methods:{
        init(formInfo,
            formInfoDetailed,
            formData,
            GUID,
            wfYwMain,
            wfYwStream,
            dqYwStream,
            dqTask){
            this.programInterface = dqTask.programInterface
            this.form.htId = wfYwMain.ywLyid
            this.streamId = dqYwStream.id
            getMainOrChild(this.streamId).then(res => {
                this.streamType = res.data.data
               //console.log("streamType======================"+res.data.data)
                this.getDataList()
            })
        },
        getFormData() {
            this.$emit("returnFormData", null);
        },
        //返回到合同创建页面
        fanHu(){
            this.showH=1
        },
        //从合同创建跳转过来执行的方法
        hetongcjC(data){
         //console.log(data);
            if(data){
                this.showH=2
                this.hetongId=data.htId
                this.getDataList();
            }

        },
        searchchangeadvanced() {
            this.searchadvanced = !this.searchadvanced;
            if(this.searchadvanced){
                this.searchheight= 'auto'
            }
        },
        //搜索
        search(){
            this.getDataList()
        },
        //获取指标列表
        getDataList () {
            if(this.streamType == 'child'){
                getPageChild({"htId": this.form.htId, "streamId":this.streamId}).then(response => {
                    this.dataList = response.data.data.records
                    this.totalPage = response.data.data.total
                })
            }else{
                getPage(Object.assign({
                    },this.form)).then(response => {
                    this.dataList = response.data.data.records
                    this.totalPage = response.data.data.total
                })
            }
        },
        // 每页数
        sizeChangeHandle(val) {
            this.pageSize = val
            this.pageIndex = 1
            this.getDataList()
        },
        // 当前页
        currentChangeHandle(val) {
            this.pageIndex = val
            this.getDataList()
        },
        ok(id){
            this.$confirm('是否要通过该指标?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                okApi(id).then(res => {
                    this.$message({
                        type: 'success',
                        message: '提交成功!'
                    });
                    this.getDataList()
                }).catch(() => {
                    this.$message({
                        type: 'error',
                        message: '提交失败!'
                    });
                    this.getDataList()
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消提交'
                });
            });
        },
        back(id){
            this.$confirm('是否要驳回该指标?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                backApi(id).then(res => {
                    this.$message({
                        type: 'success',
                        message: '驳回成功!'
                    });
                    this.getDataList()
                }).catch(() => {
                    this.$message({
                        type: 'error',
                        message: '提交失败!'
                    });
                    this.getDataList()
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消提交'
                });
            });
        },
        //批量通过
        okAll(){
            const rows = this.$refs.tableRef.selection
            const streamId = this.streamId
            if(this.streamType == 'child'){
                if(rows.length > 0){
                    this.$confirm('是否要通过' + rows.length + '条指标?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.fullscreenLoading = true;
                        okAllChildApi({"rows": rows, "streamId": streamId, "programInterface": this.programInterface}).then(res => {
                            this.$message({
                                type: 'info',
                                message: res.data.data + '条指标已通过'
                            });
                            this.fullscreenLoading = false;
                            this.getDataList()
                        }).catch(() => {
                            this.$message({
                                type: 'error',
                                message: '提交失败!'
                            });
                            this.fullscreenLoading = false;
                            this.getDataList()
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消提交'
                        });
                    });
                }else{
                    this.$message({
                        type: 'info',
                        message: '请选择指标通过!'
                    });
                }
            }else{
                if(rows.length > 0){
                    this.$confirm('是否要通过' + rows.length + '条指标?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        tbshokAllApi({"rows": rows, "streamId": streamId, "programInterface": this.programInterface}).then(res => {
                            this.$message({
                                type: 'info',
                                message: res.data.data + '条指标已通过'
                            });
                            this.getDataList()
                        }).catch(() => {
                            this.$message({
                                type: 'error',
                                message: '提交失败!'
                            });
                            this.getDataList()
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消提交'
                        });
                    });
                }else{
                    this.$message({
                        type: 'info',
                        message: '请选择指标通过!'
                    });
                }
            }
        },
        //批量驳回
        backAll(){
            const rows = this.$refs.tableRef.selection
            const streamId = this.streamId
            if(this.streamId == 'child'){
                if(rows.length > 0){
                    this.$confirm('是否要驳回' + rows.length + '条指标?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.fullscreenLoading2 = true;
                        backAllChildApi({"rows": rows, "streamId": streamId, "programInterface": this.programInterface}).then(res => {
                            this.$message({
                                type: 'info',
                                message: res.data.data + '条指标已驳回'
                            });
                            this.fullscreenLoading2 = false;
                            this.getDataList()
                        }).catch(() => {
                            this.$message({
                                type: 'error',
                                message: '提交失败!'
                            });
                            this.fullscreenLoading2 = false;
                            this.getDataList()
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消提交'
                        });
                    });
                }else{
                    this.$message({
                        type: 'info',
                        message: '请选择指标驳回!'
                    });
                }
            }else{
                if(rows.length > 0){
                    this.$confirm('是否要驳回' + rows.length + '条指标?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        tbshbackAllApi({"rows": rows, "streamId": streamId, "programInterface": this.programInterface}).then(res => {
                            this.$message({
                                type: 'info',
                                message: res.data.data + '条指标已驳回'
                            });
                            this.getDataList()
                        }).catch(() => {
                            this.$message({
                                type: 'error',
                                message: '提交失败!'
                            });
                            this.getDataList()
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消提交'
                        });
                    });
                }else{
                    this.$message({
                        type: 'info',
                        message: '请选择指标驳回!'
                    });
                }
            }
        },
        checkboxSelect (row, rowIndex) {
            if (row.tbzbStatus == "1" ) {
                return true;
            }else{
                return false;
            }
        },
        //公式
        getFormula() {

          getFormula().then(res => {
            this.formulaOptions = res.data.data;
          })
        },
        tbzbStatusFormater(row,column){
          const status = row.tbzbStatus;
          if(status==0){
            return '未提交';
          }else if(status==1){
            return '待审批';
          }else if(status==2){
            return '已驳回';
          }else if(status==3){
            return '已通过';
          }
        },
        statusFormater(row,column){
          const status = row.signLevel;
          if(status==1){
            return '一级合同';
          }else if(status==2){
            return '二级合同';
          }else if(status==3){
            return '三级合同';
          }else if(status==4){
            return '四级合同';
          }else if(status==5){
            return '五级合同';
          }
        },
    }
}
</script>

<style>

</style>
